ASP.NET的"Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用"的报错问题.

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:32:36
在GridView\FormView\DetailView的模板中,放了两个联动的DropDownList,也就是第一个选择,第二个根据第一个选择的内容进行刷新,不管怎么搞都出现"Eval()、XPath()和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用"的错误 .有人知道解决方法吗?帮帮忙啊,小弟倾囊相报.
tianyu5201的答案是错的,我测试过了,他的答案放在GridView\FormView\DetailView的模板外面,是完全可以实现联动;
但是放在GridView\FormView\DetailView的模板里面,还是弹出"Eval()、XPath()和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用"的错误 .

这个东西,你应该是用ajax做的吧,这个时候,你的第二个服务器控件DropDownList其实和html的select是一样的,没有任何区别,因为并没有通过服务器端的new ListItem()来绑定,而且服务器端也只能用Request来获得.............

我是这样绑定两个DROPDOWNLIST级联控件的

if(!this.IsPostBack)
{string strconn=ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection con=new SqlConnection(strconn);
con.Open();
SqlCommand com=new SqlCommand("select * from attend",con);
SqlDataReader sdr=com.ExecuteReader();
this.DDL_manufacturer.DataSource=sdr;
this.DDL_manufacturer.DataTextField="manufacturer";//显示的字段this.DDL_manufacturer.DataValueField="attendid";//设置主键
this.DDL_manufacturer.DataBind();
sdr.Close();
SqlCommand comid=new SqlCommand("select * from attend where attendid='"+this.DDL_manufacturer.SelectedValue+"'",con);
SqlDataReader sdrr=comid.ExecuteReader();
this.DDL_id.DataSource=sdrr;
this.DDL_id.DataTextField="attendid";//显示